package cn.tedu.springbootdemo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
 * SpringBoot内嵌了JUnit5，导入SpringBoot依赖，就会自动导入JUnit5
 * JUnit5常用的测试注解
 * @BeforeEach 、@BeforeAll、@AfterEach、@AfterAll, @Test
 */
public class JUnit5Test01 {

    private static Connection conn;

    @BeforeAll //全部测试案例执行之前
    static void beforeAll() throws SQLException {

        conn= DriverManager.getConnection("jdbc:mysql://localhost:3306" +
            "/spring_test?characterEncoding=utf8&useSSL=false&serverTimezone=Asia" +
            "/Shanghai&rewriteBatchedStatements=true","root","root");
        System.out.println(conn);
    }

    @Test
    void test01(){
        System.out.println("新增数据");
    }

    @Test
    void test02(){
        System.out.println("删除数据");
    }

    @BeforeEach //在每个测试案例之前
    void beforeEach(){
        System.out.println("准备开始进行测试");
    }

    @AfterEach //在每个测试案例之后
    void afterEach(){
        System.out.println("测试结束");
    }

    @AfterAll //在所有的测试案例之后
    static void afterAll() throws SQLException {
        System.out.println("关闭连接，释放资源");
        conn.close();
    }



}
